var TransmitData = {
    URL: '123', // 传入子页面url
    isAdd: true, // 判断编辑新增
    data: null, // 编辑数据  
    equipmentModelSub: null,
    workshopStorey: null,
    workshopInformation: null,
    productType: null,
    machineAbility: null,
    documentType: null,
    equipmentType: null,
    host: '',
    setter: ''
}
layui.use(['jquery', 'table', 'layer', 'laydate', 'utill', 'admin'], function () {
    var table = layui.table, //表格
        $ = layui.jquery,
        api = layui.api,
        layer = layui.layer,
        admin = layui.admin,
        laydate = layui.laydate,
        utill = layui.utill,
        equipmentModelSub = '',
        workshopStorey = '',
        productType = '',
        machineAbility = '',
        fii02 = '',
        documentType = '',
        workshopInformation = '',
        tableArray = null;
    TransmitData.host = api.host
    TransmitData.setter = layui.setter


    table.on('tool(equipmentModelSup)', function (obj) {
        fii02 = obj.data.fii02
        reload(equipmentModelSub, { fii02: obj.data.fii02 })
    });

    
    //设备型号
    var equipmentModelSup = tableRender(table, {
        elem: '#equipmentModelSup',
        url: api.host + '/fil/querySelectFiiFileList.json',
        method: 'post',
        height: 300,
        cols: [
            [ //表头
                {
                    type: 'numbers',
                    // field: 'ROW_ID',
                    title: '序号',
                    unresize: false,
                    event: 'loading',
                    // width: 80
                }, {
                    field: 'fii02',
                    title: '设备型号',
                    unresize: false,
                    event: 'loading',
                    // width: 90
                }, {
                    field: 'fii01',
                    title: '设备系列',
                    unresize: false,
                    event: 'loading',
                    // width: 80,
                }, {
                    field: 'tcSeriesPmc01',
                    title: '供应商',
                    unresize: false,
                    event: 'loading',
                    // width: 80,
                }, {
                    field: 'fii03',
                    title: '设备型号说明',
                    unresize: false,
                    event: 'loading',
                    // width: 80
                }
            ]
        ]
    }, function (res) {
        // 设备型号
        utill.columnCustom('#equipmentModelSup', "FiiFileVO", {
            url: api.host + '/fil/querySelectFiiFileList.json',
            done: function (res, curr, count) {
                fii02 = res.data[0].fii02
                getEquipmentModelSubList(res.data[0].fii02)
            }
        });
    })



    //监听行工具事件
    tableOn(table, 'equipmentModelSub', function (date) {
        TransmitData.isAdd = false
        TransmitData.data = date.data
        layerOpen('../src/views/home/popup/equipmentModelSub.html')
        // layer.msg('编辑操作');  
    }, function (date) {
        layer.closeAll()
        layer.msg('正在操作...', { shade: .3, time: 500 });
        comment(layui.api.host + '/fil/deleteTcEamSpDev.json', 'post', {
            fii02: fii02,
            ima01: [date.data.ima01]
        }, function (res) {
            if (res.code == '0') {
                reload(equipmentModelSub, {
                    fii02: fii02
                })
                // date.del(); //删除对应行（tr）的DOM结构
                layer.msg('操作成功', { time: 1000 })

            } else {
                layer.msg('操作失败', { time: 1000 })
            }
        }, true)
    })
    table.on('checkbox(equipmentModelSub)', function (obj) { // checkbox 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        tableArray = table.checkStatus('equipmentModelSub').data // 获取勾选数据 
    });

    // // 设备型号
    function getEquipmentModelSubList(fii02) {
        equipmentModelSub = tableRender(table, {
            where: {
                fii02: fii02
            },
            elem: '#equipmentModelSub',
            url: api.host + '/fil/QuerySpareParts.json',
            method: 'post',
            height: 300,
            cols: [
                [ //表头
                    {
                        type: 'checkbox'
                    }

                    , {
                        type: 'numbers',
                        title: '序号',
                    }, {
                        width: 165,
                        align: 'center',
                        toolbar: '#onlyDel',
                        title: '操作',
                    }, {
                        field: 'ima01',
                        title: '关联备品备件编号',
                    }, {
                        field: 'ima02',
                        title: '关联备品备件名称',
                    }, {
                        field: 'ima021',
                        title: '关联备品备件规格',
                    }
                ]
            ]
        }, function (res) {
        })
        TransmitData.equipmentModelSub = equipmentModelSub
    }

    //厂房资料 workshopInformation
    //监听行工具事件
    tableOn(table, 'workshopInformation', function (date) {

    }, function (date) {
        layer.closeAll()
        layer.msg('正在操作...', { shade: .3, time: 500 });
        comment(layui.api.host + '/tcEamFactory/deleteFactory.json', 'post',JSON.stringify([date.data.tcFtyId]), function (res) {
            if (res.code == '0') {
                reload(workshopInformation, {})
                layer.msg(res.message)

            } else {
                layer.msg(res.message)
            }
        })
    })
    table.on('checkbox(#workshopInformation)', function (obj) { 
        tableArray = table.checkStatus('workshopInformation').data // 获取勾选数据 
    });

    TransmitData.workshopInformation = workshopInformation = tableRender(table, {
        elem: '#workshopInformation',
        url: api.host + '/tcEamFactory/selectDevFactory.json',
        method: 'post',
        cols: [
            [ //表头
                {
                    type: 'checkbox'
                }

                , {
                    title: '序号',
                    type: 'numbers'
                }, {
                    align: 'center',
                    toolbar: '#onlyDel',
                    title: '操作',
                }, {
                    field: 'tcFtyId',
                    title: '厂房编码',
                }, {
                    field: 'azp02',
                    title: '公司',
                }, {
                    field: 'tcFtyName',
                    title: '厂房名称',
                }, {
                    field: 'tcFtyDsc',
                    title: '厂房描述',
                }
            ]
        ]
    }, function (res) {
    })



    //厂房楼层 workshopStorey
    //监听行工具事件
    tableOn(table, 'workshopStorey', function (date) {

    }, function (date) {
        layer.closeAll()
        layer.msg('正在操作...', { shade: .3, time: 500 });
        comment(layui.api.host + '/tcEamDevFtyFactory/deleteFloor.json', 'post', JSON.stringify([date.data.tcFlrId]), function (res) {
            if (res.code == '0') {
                reload(workshopStorey, {})
                layer.msg('操作成功', { time: 1000 })

            } else {
                layer.msg('操作失败', { time: 1000 })
            }
        })
    })
    table.on('checkbox(workshopStorey)', function (obj) { // checkbox 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        tableArray = table.checkStatus('workshopStorey').data // 获取勾选数据 
    });
    TransmitData.workshopStorey = workshopStorey = tableRender(table, {
        elem: '#workshopStorey',
        url: api.host + '/tcEamDevFtyFactory/selectFtyFloor.json',
        method: 'post',
        cols: [
            [ //表头
                {
                    type: 'checkbox'
                }

                , {
                    title: '序号',
                    type: 'numbers'
                }, {
                    width: 165,
                    align: 'center',
                    toolbar: '#onlyDel',
                    title: '操作',
                }, {
                    field: 'tcFlrId',
                    title: '楼层编码',
                }, {
                    field: 'tcFtyName',
                    title: '厂房',
                }, {
                    field: 'tcFlrName',
                    title: '楼层名称',
                }, {
                    field: 'tcFlrDsc',
                    title: '楼层描述',
                }
            ]
        ]
    }, function (res) {
    })


    //产品类型 productType
    //监听行工具事件
    tableOn(table, 'productType', function (date) {
        TransmitData.data = date.data
        TransmitData.isAdd = false
        layerOpen('../src/views/home/popup/productType.html')
        // layer.msg('编辑操作');
    }, function (date) {
        layer.closeAll()
        layer.msg('正在操作...', { shade: .3, time: 500 });
        comment(layui.api.host + '/fia/deleteDevProduct.json', 'post', [date.data.tcProdId], function (res) {
            if (res.code == '0') {
                reload(productType, {})
                // date.del(); //删除对应行（tr）的DOM结构
                layer.msg('操作成功', { time: 1000 })
            } else {
                layer.msg('操作失败', { time: 1000 })
            }
        }, true)

    })
    table.on('checkbox(productType)', function (obj) { // checkbox 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        tableArray = table.checkStatus('productType').data // 获取勾选数据 
    });

    TransmitData.productType = productType = tableRender(table, {
        elem: '#productType',
        url: api.host + '/fia/selectDevProduct.json',
        method: 'post',
        cols: [
            [ //表头
                {
                    type: 'checkbox'
                }

                , {
                    title: '序号',
                    type: 'numbers'
                    // width: 80
                }, {
                    width: 165,
                    align: 'center',
                    toolbar: '#barDemo',
                    title: '操作',
                }, {
                    field: 'tcProdCode',
                    title: '产品类型编号',
                    // width: 90
                }, {
                    field: 'tcProdName',
                    title: '产品类型名称',
                    // width: 80,
                }, {
                    field: 'tcProdDsc',
                    title: '产品类型说明',
                    // width: 80
                }
            ]
        ]
    }, function (res) {
    })






    //机台能力 machineAbility
    //监听行工具事件
    tableOn(table, 'machineAbility', function (date) {
        TransmitData.data = date.data
        TransmitData.isAdd = false
        layerOpen('../src/views/home/popup/machineAbility.html')
        // layer.msg('编辑操作');
    }, function (date) {
        layer.closeAll()
        layer.msg('正在操作...', { shade: .3, time: 500 });
        comment(layui.api.host + '/fia/deleteDevCapaCity.json', 'post', [date.data.tcCapId], function (res) {
            if (res.code == '0') {
                reload(machineAbility, {})
                table.reload('#machineAbility')
                // date.del(); //删除对应行（tr）的DOM结构
                layer.msg('操作成功', { time: 1000 })

            } else {
                layer.msg('操作失败', { time: 1000 })
            }
        }, true)
    })
    table.on('checkbox(machineAbility)', function (obj) { // checkbox 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        tableArray = table.checkStatus('machineAbility').data // 获取勾选数据 
    });
    TransmitData.machineAbility = machineAbility = tableRender(table, {
        elem: '#machineAbility',
        url: api.host + '/fia/selectDevCapaCity.json',
        method: 'post',
        cols: [
            [ //表头
                {
                    type: 'checkbox'
                }

                , {
                    // field: 'username',
                    title: '序号',
                    type: 'numbers'
                    // width: 80
                }, {
                    width: 165,
                    align: 'center',
                    toolbar: '#barDemo',
                    title: '操作',
                }, {
                    field: 'tcCapCode',
                    title: '机台能力编号',
                    // width: 90
                }, {
                    field: 'tcCapName',
                    title: '机台能力名称',
                    // width: 80,
                }, {
                    field: 'tcCapDsc',
                    title: '机台能力描述',
                    // width: 80
                }
            ]
        ]
    }, function (res) {
    })
    table.on('checkbox(documentType)', function (obj) { // checkbox 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        tableArray = table.checkStatus('documentType').data // 获取勾选数据 
    });
    TransmitData.documentType = documentType = tableRender(table, {
        elem: '#documentType',
        url: api.host + '/do/selectCatgList.json',
        method: 'post',
        cols: [
            [ //表头
                {
                    type: 'checkbox'
                }

                , {
                    // field: 'username',
                    title: '序号',
                    type: 'numbers'
                    // width: 80
                }, {
                    width: 165,
                    align: 'center',
                    toolbar: '#onlyDelEdit',
                    title: '操作',
                }, {
                    field: 'tcCatgCode',
                    title: '文档类型编码',
                    // width: 90
                }, {
                    field: 'tcCatgName',
                    title: '文档类型名称',
                    // width: 80,
                }, {
                    field: 'tcCatgDsc',
                    title: '文档类型说明',
                    // width: 80
                }
            ]
        ]
    }, function (res) {
    })



    // 设备类型 equipmentType
    // 监听行工具事件
    tableOn(table, 'equipmentType', function (date) {
        TransmitData.data = date.data
        TransmitData.isAdd = false
        layerOpen('../src/views/home/popup/equipmentTypecs.html')
    }, function (date) {
        var datas = date.data.fic01;
        layer.closeAll()
        layer.msg('正在操作...', { shade: .3, time: 500 });
        // 删除接口
        comment(layui.api.host + '/fil/deleteFicFiles.json', 'post', { fic01: datas }, function (res) {
            if (res.code == '0') {
                reload(equipmentType, {})
                layer.msg('操作成功', { time: 1000 })

            } else {
                layer.msg('操作失败', { time: 1000 })
            }
        }, true)
    })
    table.on('checkbox(equipmentType)', function (obj) { // checkbox 是工具条事件名，test 是 table 原始容器的属性 lay-filter="对应的值"
        tableArray = table.checkStatus('equipmentType').data // 获取勾选数据 
    });
    TransmitData.equipmentType = equipmentType = tableRender(table, {
        elem: '#equipmentType',
        url: api.host + '/fil/querySelectFicFileList.json',
        method: 'post',
        cols: [
            [ //表头
                {
                    type: 'checkbox'
                }

                , {
                    title: '序号',
                    type: 'numbers'
                }, {
                    width: 165,
                    align: 'center',
                    toolbar: '#barDemo',
                    title: '操作',
                }, {
                    field: 'fic01',
                    title: '设备类型编码',
                }, {
                    field: 'fic02',
                    title: '设备类型名称',
                }, {
                    field: 'tcTypeSupFic01',
                    title: '上级设备类型',
                }, {
                    field: 'tcTypeLevel',
                    title: '设备类型级别',
                }, {
                    field: 'tcTypeDsc',
                    title: '设备类型说明',
                }
            ]
        ]
    }, function (res) {
    })

    // 设备型号
    // $('.Second').on('click', '.add-btn', function () {
    //     TransmitData.isAdd = true
    //     layerOpen('../src/views/home/popup/equipmentModelSub.html')
    // })

    // // 产房资料
    // $('.thirdlyTable').on('click', '.add-btn', function () {
    //     TransmitData.isAdd = true
    //     layerOpen('../src/views/home/popup/workshopInformation.html')
    // })

    // 厂房楼层 
    // $('.fourthTable').on('click', '.add-btn', function () {
    //     TransmitData.isAdd = true
    //     layerOpen('../src/views/home/popup/workshopStorey.html')
    // })
    // 产品类型
    // $('.fiveTable').on('click', '.add-btn', function () {
    //     TransmitData.isAdd = true
    //     layerOpen('../src/views/home/popup/productType.html')
    // })

    // 机台能力
    // $('.sexTable').on('click', '.add-btn', function () {
    //     TransmitData.isAdd = true
    //     layerOpen('../src/views/home/popup/machineAbility.html')
    // })
    //文档类型 tcCatgId /do/delDocument.json
    $('.seventhTable').on('click', '.add-btn', function () {
        TransmitData.isAdd = true
        layerOpen('../src/views/home/popup/documentType.html')
        
    })
    // 文档类型删除{需要核对}
    table.on("tool(documentType)", function (obj) {
        if (obj.event == 'edit') {
            tableOn(table, 'documentType', function (obj) {
                TransmitData.data = obj.data
                TransmitData.isAdd = false
                layerOpen('../src/views/home/popup/documentType.html')
            });
        }
    })

    // 设备类型
    $('.eighthTable').on('click', '.add-btn', function () {
        TransmitData.isAdd = true
        layerOpen('../src/views/home/popup/equipmentTypecs.html')
    })
});